@extends('layouts.admin')
@section('style')
    <style type="text/css">
        .box_form .layui-input-inline {
            width: 480px;
            min-width: 200px;
        }
        .layui-form-select dl {
            z-index: 99999;
        }
    </style>
@endsection
@section('content')
    <div class="admin_main">
        <div class="admin_header_fixed">
            <div class="admin_header clearfix">
                <div class="title"><i></i>编辑商品</div>
                <div class="action">
                    <b></b>
                    <div class="layui-btn-group layui-btn-group-only">
                        <a class="layui-btn layui-btn-primary layui-btn-small " href="{{ url('goods') }}">
                            <i class="fa fa-reply"></i> 返回商品列表
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="admin_base">
            <div class="box_form">
                <div class="box_content">
                    <form method="post" action="{{ url('goods/'.$vo->id) }}" id="VoForm" class="layui-form" novalidate="1">
                        {{ csrf_field() }}
                        {{ method_field('PUT') }}
                        <fieldset class="layui-elem-field">
                            <legend style="font-size:16px;margin-bottom:10px">基本信息</legend>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span>宝贝ID</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="item_id" placeholder="请输入宝贝ID" value="{{ $vo->item_id }}" id="item_id"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span>宝贝标题</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="item_title" placeholder="请输入宝贝标题" value="{{ $vo->item_title }}" id="item_title"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span>所属店铺</label>
                                <div class="layui-input-inline">
                                    <select name="shop_id" style="z-index:9999;">
                                        <option value="">请选择所属店铺</option>
                                        @foreach($shops as $shop)
                                            <option value="{{ $shop->id }}" @if($vo->shop_id==$shop->id) selected @endif >{{ $shop->title }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span>商品价格</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="price" placeholder="请输入商品价格" value="{{ $vo->price }}"
                                           id="seller_name" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span>*</span>商品佣金</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="commission" placeholder="请输入商品佣金" value="{{ $vo->commission }}"
                                           id="seller_name" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">&nbsp;</label>
                                <div class="layui-input-block admin_bottom" style="">
                                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save">
                                        立即提交
                                    </button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
        <div class="admin_bottom"></div>
    </div>
@endsection
@section('script')
    <script type="text/javascript" src="{{ asset('files/ueditor/ueditor.config.js') }}"></script>
    <script type="text/javascript" src="{{ asset('files/ueditor/ueditor.all.js') }}"></script>
    <script type="text/javascript" src="{{ asset('files/ueditor/lang/zh-cn/zh-cn.js') }}"></script>
    <script type="text/javascript">
        var city_id = parseInt("{{ $vo->city_id }}");
        var area_id = parseInt("{{ $vo->area_id }}");
        var _refer_url = document.referrer;
        layui.use(['form','laydate', 'element', 'layer', 'utils', 'formField'], function () {
            var form = layui.form;
            var element = layui.element;
            var URL = layui.utils.URL;
            var errorTip = layui.utils.errorTip;
            var $ = layui.$;
            var layDate = layui.laydate;


            form.on('submit(save)', function (data) {
                var url = $(data.form).prop('action');
                var data = data.field;
                URL.post(url, data, {
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg(res.message, {icon: 6, times: 2000}, function () {
                                if(typeof _refer_url!='undefined'){
                                    document.location.href = _refer_url;
                                }else{
                                    document.location.href = res.data.redirect;
                                }
                            })
                        } else {
                            var errors = res.errors;
                            if (typeof errors != 'undefined') {
                                errorTip(errors);
                            } else {
                                layer.msg(res.message, {icon: 5, times: 2000});
                            }
                        }
                    }
                })
                return false;
            })
        });
    </script>
@endsection